// pages/businessman/businessman.js
var common = require("../../utils/util.js");
Page({

  /**
   * 页面的初始数据
   */
  data: {
  data:[],
  buniessdata:[],
  pagesize:10,
  selected:false,
  sta:true,
  pageIndex: 1,
  navindex:0,
  refresh:true,
  ehcId:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this
    //ajax

    common.ajax({
      url: 'Exhibition/GetShowRoom',
      data: {

      },
      loading: '',
      userinfo: false,
      success: function (res) {
        if (res.message != 'success') {
          console.log(1)
        } else {
          that.setData({
            data: res.data,
            ehcId: res.data[0].SrmID
          })
          that.setData({
            pageIndex: that.data.pageIndex,
            
          })
          console.log(that.data.ehcId)
          that.find()
         
        }
      }
    })
    //ajax
   //ajax

    
    
    
  },

  companydetail: function (event) {
    var that = this
    that.setData({
      AtrID: event.currentTarget.dataset.id,
    })
    wx.navigateTo({
      url: '../companyDetail/companyDetail?atrID=' + that.data.AtrID
    })
    console.log(that.data.AtrID)
  },
  searchTitl: function (event) {
    this.setData({
      searchT: event.detail.value
    })
  },
  search: function () {
    var that = this;
    wx.navigateTo({
      url: '../search/search'
    })
  },
  find_company:function(event){
    //ajax
    var that = this
    that.setData({
      pageIndex: 1,
      ehcId: event.currentTarget.dataset.id,
      navindex: event.currentTarget.dataset.index,
      buniessdata:[]
    })
    that.find()
  },
  find:function(){
    //ajax
    var that = this
    console.log(that.data.ehcId)
    console.log(9999)
   common.ajax({
      url: 'Exhibition/GetActorListByEhcID',
      data: {
        ehcId: that.data.ehcId,
        pageIndex: that.data.pageIndex,
        pageSize: that.data.pagesize
      },
      // loading: '',
      userinfo: false,
      success: function (res) {
        if (res.message != 'success') {
          console.log(1)
        } else {
          
          console.log(that.data.buniessdata)
          if (res.data == null) {
            that.setData({
              refresh: false
            })
            return false
          }
          if (res.data.length < that.data.pagesize) {
            that.setData({
              refresh: false
            })
          } else {
            console.log(666)
            that.data.pageIndex++
            that.setData({
              pageIndex: that.data.pageIndex
            })
            console.log(that.data.pageIndex)
          }
          if (res.data.length > 0) {
            that.data.buniessdata = that.data.buniessdata.concat(res.data)
            that.setData({
              buniessdata: that.data.buniessdata
            })
            console.log(that.data.buniessdata)
          }
        }
      }
    })
    //ajax
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    
    var that = this
    that.setData({
      refresh: true,
      pageIndex: 1,
      buniessdata:[]
      
    });
    console.log()
      that.find()
      wx.stopPullDownRefresh()
   
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    
    var that = this;
    // console.log(that.data.refresh)
    if (that.data.refresh) {
     
      that.find()
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})